<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="nav" content="0" />
<meta name="acc" content="check-1" />
<title>日常监督</title>
<script type="text/javascript" charset="utf-8"
	src="<c:url value='/KindEditor/kindeditor.js'/>"></script>
<script type="text/javascript">
function  getcheckResult(){
	var date = new Date();
	$.get("${ctx}/quality/check_result!info.action?cid=${id}&decorator=open&confirm=true&time="+date,function(data){
		$("#frame").html(data);
	});
}
	$(document).ready(function() {
		$("#flowCode").focus();
		$("#inputForm").validate({
			event : "blur",
			isTip : true
		});
		
		$("#process").click(function() {
			KE.sync("content");
			$("#inputForm").attr("action",
				"${ctx}/quality/check!second.action");
			$("#inputForm").submit();
		});
		getcheckResult();
		$("#prepareDate1").addClass("Wate").bind("click", function() {
			WdatePicker({
				skin : 'whyGreen',
				minDate : '#F{$dp.$D(\'checkDate\')}',
				maxDate : '#F{$dp.$D(\'checkEndDate\')}',
				dateFmt : 'yyyy-MM-dd'
			});
		});
		
		$("#save").click(function (){
			KE.sync("content1");
			var projectId = $("input[name='projectId']").val();
			var checkId = $("input[name='id']").val();
			var prepareDate = $("input[name='prepareDate1']").val();
			var content = $("textarea[name='content1']").val();
			var type = $("select[name='type1']").val();
			var remark = $("textarea[name='remark1']").val();
			$.post("${ctx}/quality/check_result!save.action",{projectId:projectId,content:content,prepareDate:prepareDate,type:type,remark:remark,cid:checkId},function(data){
				getcheckResult();
			});
			//$("#inputForm").attr("action","${ctx}/quality/check_result!save.action");
			//$("#inputForm").submit();
		});
	});

	var i = 1;
	function addFile(divName, fileName) {
		var dv = document.getElementById(divName);

		var file = document.createElement("input");
		file.type = "file";
		file.name = fileName;
		file.id = fileName + i;
		dv.appendChild(file);

		var btn = document.createElement("input");
		btn.type = "button";
		btn.id = btn.name = "btn" + i;
		btn.value = "删除";

		btn.onclick = function() {
			var b = document.getElementById(btn.id);
			dv.removeChild(b.nextSibling);
			dv.removeChild(b.previousSibling);
			dv.removeChild(b);
		}

		dv.appendChild(btn);
		dv.appendChild(document.createElement("BR"));

		i++;
	}
	
	KE.show({
		id : 'content1',
		cssPath : './index.css',
		afterCreate : function(id) {
			KE.event.ctrl(document, 13, function() {
				KE.sync(id);
				document.forms['inputForm'].submit();
			});
			KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
				KE.sync(id);
				document.forms['inputForm'].submit();
			});
		}
	});
</script>
</head>
<body>
	<form action="${ctx }/quality/check!save.action" method="post"
		id="inputForm" class="yform" enctype="multipart/form-data">
		<div id="caption">
			<h6>${licenseplateNumber}编制监督检查</h6>
		</div>
		<input type="hidden" name="id" id="id" value="${id }"> <input
			type="hidden" name="projectId" id="projectId"
			value="${empty param.projectId ? projectId : param.projectId }">
		<input type="hidden" name="checkType" id="checkType"
			value="${checkType}">
		<div>
			<fieldset>
				<legend>监督检查基本情况</legend>
				<table class="noborder">
					<tr class="type-text">
						<td>工程名称</td>
						<td colspan="3"><pt:labels type="proj"
								argument1="${empty param.projectId ? projectId : param.projectId }"
								single="true"></pt:labels></td>
					</tr>
				<c:if test="${checkType !='1'}">
				<tr class="type-text">
					<td>检查开始时间</td>
					<td><input type="text" name="checkDate" id="checkDate"
						value="${checkDate }" class="required"></td>
					<td>检查结束时间</td>
					<td><input type="text" name="checkEndDate" id="checkEndDate"
						value="${checkEndDate }" class="required"></td>
				</tr>
				</c:if>
				<c:if test="${checkType =='1'}">
				<tr class="type-text">
					<td>检查时间</td>
					<td><input type="text" name="checkDate" id="checkDate"
						value="${checkDate }" class="required"></td>
					<td></td><td></td>
				</tr>
				</c:if>
					<tr class="type-text">
						<td>检查主要内容</td>
						<td colspan="3"><textarea name="content" id="content" >${content }</textarea>
						</td>
					</tr>
					<tr class="type-text">
						<td>备注</td>
						<td colspan="3"><textarea name="remark" id="remark">${remark }</textarea>
						</td>
					</tr>
					<tr class="type-text">
						<td><input type="button" value="添加上传"
							onclick="addFile('sources','upload')"></td>
						<td colspan="3" id="sources"></td>
					</tr>
				</table>
				<c:if test="${not empty attachmentSet }">
					<div id="caption">
						<h6>${licenseplateNumber}已有附件</h6>
					</div>
					<table>
						<c:forEach items="${attachmentSet }" var="attachment"
							varStatus="state">
							<tr id="tr${state.index }">
								<td colspan="4"><a title="下载"
									href="${ctx}/servlet/annex?id=${attachment.id}">${attachment.upfileFileName}(${attachment.type})<fmt:formatDate
											value="${attachment.fileTime}" pattern="yyyy-MM-dd" /> </a> <span
									onclick="deleteAttachmentById('${attachment.id}','tr${state.index }')"
									class="delete" title="删除附件"></span>
								</td>
							</tr>
						</c:forEach>
					</table>
				</c:if>
			</fieldset>
			<input type="hidden" id="cid" name="cid" value="${id }">
			<fieldset>
				<legend>添加监督检查情况汇报</legend>
				<table class="noborder">
					<tr class="type-text">
						<td width="100">问题类型</td>
						<td><pt:code category="3011" name="type1" width="120"></pt:code></td>
						<c:if test="${checkType !='1'}">
						<td>发现时间</td>
						<td><input type="text" id="prepareDate1" name="prepareDate1"  >
						</td>
						</c:if>
						<c:if test="${checkType =='1'}">
						<td><input type="hidden" id="prepareDate1" name="prepareDate1" value="${checkDate }" ></td>
						<td></td>
						</c:if>
					</tr>
					<tr class="type-text">
						<td>问题描述</td>
						<td colspan="3"><textarea name="content1" id="content1" style="width: 90%"></textarea>
						</td>
					</tr>
					<tr class="type-text">
						<td>备注</td>
						<td colspan="3"><textarea name="remark1"></textarea></td>
					</tr>
					<tr class="type-text">
						<td colspan="4" align="center"><div class="type-button"><input type="button"
							value="添加" id="save" name="save"></div>
						</td>
					</tr>
				</table>
			</fieldset>
			<fieldset>
				<legend>监督检查情况汇报列表</legend>
				<div id="frame"></div>
			</fieldset>
		</div>
		<div class="type-button">
			<input type="submit" class="submit" value="暂存" />
			<c:if test="${status == '01' || status == null }">
				<input type="button" class="submit" value="提交" id="process">
			</c:if>
			<input type="button" value="返回" class="reset"
				onclick="history.back()" />
		</div>
	</form>
</body>
</html>